package com.pachong.android.baseuicomponent.fragment;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.pachong.android.baseuicomponent.R;
import com.pachong.android.baseuicomponent.refreshable.IRefreshable;
import com.pachong.android.baseuicomponent.refreshable.OnRefreshListener;
import com.pachong.android.baseuicomponent.refreshable.swiperefresh.SwipeRefreshViewHelper;


public abstract class SwipeGridFragment extends GridFragment implements IRefreshable {
	private SwipeRefreshViewHelper mSwipeRefreshViewHelper;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		mSwipeRefreshViewHelper = new SwipeRefreshViewHelper(getActivity(), this);
		View view = super.onCreateView(inflater, container, savedInstanceState);
		return view;
	}

	@Override
	public View createRecyclerContentView(LayoutInflater inflater) {
		View view = inflater.inflate(R.layout.common_swipelayout_recyclerview_content, null);
		RecyclerView rv = (RecyclerView) view.findViewById(R.id.recyclerview);
		setRecyclerView(rv);
		View refreshView = view.findViewById(R.id.refreshLayout);
		mSwipeRefreshViewHelper.initRefreshView(refreshView, this);
		return view;
	}


	public SwipeGridFragment(int spanCount) {
		super(spanCount);
	}


	/**
	 * 回调方法，开始刷新
	 */
	@Override
	public void onStartRefreshing() {
	}


	/**
	 * 隐藏刷新控件
	 */
	@Override
	public void hideRefreshView() {
		mSwipeRefreshViewHelper.hideRefreshView();
	}


	/**
	 * 显示刷新控件
	 */
	@Override
	public void showRefreshView() {
		mSwipeRefreshViewHelper.showRefreshView();
	}


	/**
	 * 设置是否需要下拉刷新的功能
	 *
	 * @param enable
	 */
	@Override
	public void setPullToRefreshEnable(boolean enable) {
		mSwipeRefreshViewHelper.setPullToRefreshEnable(enable);
	}

	/**
	 * 设置向下滑动刷新的listener
	 * user一般不需要设置这个东西，回调onStartRefreshing足够了。
	 *
	 * @param listener
	 */
	@Override
	public void setOnRefreshListener(OnRefreshListener listener) {
		mSwipeRefreshViewHelper.setOnRefreshListener(listener);
	}




}
